package com.suneast.suneaststore.modules.personal.wallet;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.suneast.suneaststore.R;
import com.suneast.suneaststore.ui.fragments.BaseFragment;

import java.text.DecimalFormat;

import butterknife.BindView;
import butterknife.OnClick;

public class BalanceFragment extends BaseFragment {
    @Override
    public int setLayout() {
        return R.layout.fragment_balance;
    }

    @BindView(R.id.toolbar)
    Toolbar toolbar;

    @BindView(R.id.tv_total_value)
    TextView balanceValueTv;

    private double balanceValue = 0.00;

    public BalanceFragment withBalanceValue(double value) {
        balanceValue = value;
        return this;
    }

    @OnClick({R.id.img_top_up, R.id.tv_top_up, R.id.tv_balance_tip, R.id.img_go_top_up,
            R.id.img_withdraw_deposit, R.id.tv_withdraw_deposit, R.id.tv_withdraw_tip,
            R.id.tv_withdraw_value, R.id.img_go_withdraw, R.id.img_coin, R.id.tv_coin,
            R.id.tv_coin_value, R.id.img_go_coin, R.id.img_bill, R.id.tv_bill, R.id.img_go_bill})
    public void onViewClick(View view) {
        switch (view.getId()) {
            case R.id.img_top_up:
            case R.id.tv_top_up:
            case R.id.tv_balance_tip:
            case R.id.img_go_top_up: {
                start(new TopUpFragment());
            }
            break;
            case R.id.img_withdraw_deposit:
            case R.id.tv_withdraw_deposit:
            case R.id.tv_withdraw_tip:
            case R.id.tv_withdraw_value:
            case R.id.img_go_withdraw: {
                start(new WithdrawFragment());
            }
            break;
            case R.id.img_coin:
            case R.id.tv_coin:
            case R.id.tv_coin_value:
            case R.id.img_go_coin: {
                start(new CoinFragment());
            }
            break;
            case R.id.img_bill:
            case R.id.tv_bill:
            case R.id.img_go_bill: {
                start(new WalletBillFragment());
            }
            break;
        }
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, @NonNull View rootView) {
        initView();
    }

    private void initView() {
        toolbar.setNavigationOnClickListener(v -> pop());
        DecimalFormat df = new DecimalFormat("0.00");
        balanceValueTv.setText(df.format(balanceValue));
    }
}
